package com.kajespero.json.helper;


public class NumberUtils {

	@SuppressWarnings("unchecked")
	public static <N extends Number> N convert(Object source, Class<?> target) {
		if (source instanceof Number) {
			if(target.getName().equals(Long.class.getName())){
				Number num = Long.decode(source.toString());
				return (N) num;
			}
			if(target.getName().equals(Integer.class.getName())){
				Number num = Integer.decode(source.toString());
				return (N) num;
			}
			if(target.getName().equals(Double.class.getName())){
				Number num = Double.parseDouble(source.toString());
				return (N) num;
			}
			if(target.getName().equals(Float.class.getName())){
				Number num = Float.parseFloat(source.toString());
				return (N) num;
			}
			
		}
		return null;
	}

}
